﻿using BookManage.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManage
{
    public partial class frmMain : Form
    {
        
        public frmMain()
        {
            InitializeComponent();
            InitMenu();
        }

        private void InitMenu()
        {
            Reader reader = frmLogin.reader;//获取登录用户的读者信息
            //图书管理 ToolStripMenuItem.Visible=true;//是否可见
            //图书管理 ToolStripMenuItem.Available=false;//是否活动
            图书管理ToolStripMenuItem.Enabled = reader.IsBookAdmin();//是否能用;图书管理员
            读者管理ToolStripMenuItem.Enabled = (reader.IsReaderAdmin() || reader.IsSystemAdmin());//读者管理员或系统管理员
            借阅管理ToolStripMenuItem.Enabled = reader.IsBorrowAdmin();//借阅管理员
            权限管理ToolStripMenuItem.Enabled = reader.IsSystemAdmin();//系统管理员
            tssUser.Text = "登录用户：" + reader.rdName + " | " + reader.rdDept;
            TextToReader();
        }
        #region 获取读者信息
        private void TextToReader()
        {
            Reader reader = frmLogin.reader;//获取登录用户的读者信息
            textrdID.Text = Convert.ToString(reader.rdID);
            textrdName.Text = reader.rdName;
            textrdPwd.Text = reader.rdPwd;
            textrdSex.Text = reader.rdSex;
            textBorrowQty.Text = Convert.ToString(reader.rdBorrowQty);
            textrdStatus.Text = reader.rdStatus;
            textAdminRole.Text = Convert.ToString(reader.rdAdminRoles);
            textrdType.Text = Convert.ToString(reader.rdType);
            textrdDept.Text = reader.rdDept;
            textrdPhone.Text = reader.rdPhone;
            textrdEmail.Text = reader.rdEmail;
            dtpDate.Text = Convert.ToString(reader.rdDateReg);
            if (reader.rdPhoto == null)
            {
                pictureBox.Image = null;
            }
            else
            {
                MemoryStream ms = new MemoryStream(reader.rdPhoto);
                Image imgPhoto = Bitmap.FromStream(ms, true);
                pictureBox.Image = imgPhoto;
            }
        }
        #endregion

        private void frmMain_Load(object sender, EventArgs e)
        {

        }
        private void 图书信息维护ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmBook();
            form.Show();
        }
        private void 借书证管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmReader();
            form.Show();
        }
        private void 读者类型管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmReaderType();
            form.Show();
        }
        private void 权限管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmManage();
            form.Show();
        }
        private void 密码修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmMdyPwd();
            form.Show();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 借书续借还书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmBorrow();
            form.Show();
        }

        private void 图书管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void 读者查询ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
           
        }

        private void 罚款ToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void 图书查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmSelectBook();
            form.Show();
        }

        private void 查询借阅记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmSelectBorrow();
            form.Show();
        }

        private void 超期罚款ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           /* Form form = new frmPayPunish();
            form.Show();*/
        }
        private void 还书意外ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 查询本人借书证信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = new frmSelectOwnRD();
            form.Show();
        }
    }
}
